package com.modbus.tool.common;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

/**
 * 后端统一返回结果
 *
 * @param <T>
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class Result<T> implements Serializable {

    private Integer code; //编码：0失败; 1成功;
    private String msg; //错误信息
    private T data; //数据
    private String successMsg;

    public static <T> Result<T> success() {
        Result<T> result = new Result<>();
        result.code = 200;
        return result;
    }

    public static <T> Result<T> success(T object) {
        Result<T> result = new Result<>();
        result.data = object;
        result.code = 200;
        return result;
    }

    public static <T> Result<T> successDataAndMeg(T object, String successMsg) {
        Result<T> result = new Result<>();
        result.data = object;
        result.code = 200;
        result.successMsg = successMsg;
        return result;
    }

    public static <T> Result<T> successMsg(String successMsg) {
        Result<T> result = new Result<>();
        result.code = 200;
        result.successMsg = successMsg;
        return result;
    }

    public static <T> Result<T> error(String msg) {
        Result<T> result = new Result<>();
        result.msg = msg;
        result.code = 500;
        return result;
    }


}